﻿using System;

namespace SimpleFeedBindingsLibrarySLTest
{
    public class MiscHelpers
    {
        static public string XMLEncode(string i_String)
        {
            System.Text.StringBuilder StringBuilder = new System.Text.StringBuilder(i_String);

            StringBuilder = StringBuilder.Replace("&", "&amp;");
            StringBuilder = StringBuilder.Replace(">", "&gt;");
            StringBuilder = StringBuilder.Replace("<", "&lt;");
            StringBuilder = StringBuilder.Replace("\"", "&quot;");
            StringBuilder = StringBuilder.Replace("'", "&#39;");

            return StringBuilder.ToString();
        }

        static public string XMLDecode(string i_String)
        {
            System.Text.StringBuilder StringBuilder = new System.Text.StringBuilder(i_String);

            StringBuilder = StringBuilder.Replace("&amp;", "&");
            StringBuilder = StringBuilder.Replace("&gt;", ">");
            StringBuilder = StringBuilder.Replace("&lt;", "<");
            StringBuilder = StringBuilder.Replace("&quot;", "\"");
            StringBuilder = StringBuilder.Replace("&#39;", "'");

            return StringBuilder.ToString();
        }
    }
}
